package com.woniu.his.cms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.cms.client.NonDrugItemRecordClient;
import com.woniu.his.cms.client.param.AddNonDrugItemRecordParam;
import com.woniu.his.cms.client.param.UpdateNonDrugItemRecord;
import com.woniu.his.cms.client.result.NonDrugItemResult;
import com.woniu.his.cms.service.NonDrugItemRecordService;
import com.woniu.his.cms.service.dto.NonDrugItemDto;
import com.woniu.his.cms.service.param.AddNonDrugItemRecordServiceParam;
import com.woniu.his.cms.service.param.UpdateNonDrugItemServiceRecord;
import com.woniu.his.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Slf4j
@RequestMapping("/cms")
public class NonDrugItemRecordApiImpl implements NonDrugItemRecordClient {

    @Resource
    private NonDrugItemRecordService nonDrugItemRecordService;

    @Override
    public Result addNonDrugItemRecord(@Valid AddNonDrugItemRecordParam param) {

        log.info("开立项目，传回来的数据：{}",param);
        AddNonDrugItemRecordServiceParam serviceParam= BeanUtil.copyProperties(param,AddNonDrugItemRecordServiceParam.class);
        nonDrugItemRecordService.addNonDrugItemRecord(serviceParam);
        return Result.getInstance();
    }

    @Override
    public Result deleteNonDrugItemRecord(Long id) {

        log.info("作废非药品项目记录传回来的ID：{}",id);
        nonDrugItemRecordService.deleteNonDrugItemRecord(id);
        return Result.getInstance();
    }

    @Override
    public Result updateNonDrugItemRecord(UpdateNonDrugItemRecord param) {

        log.info("更新上传的数据：{}",param);
        UpdateNonDrugItemServiceRecord record=BeanUtil.copyProperties(param,UpdateNonDrugItemServiceRecord.class);
        nonDrugItemRecordService.updateNonDrugItemRecord(record);
        return Result.getInstance();
    }

    @Override
    public Result<NonDrugItemResult> queryNonDrugItemByBillId(Long billId) {
        log.info("根据账单id查询非药品项目条目：{}",billId);
        NonDrugItemDto nonDrugItemDto = nonDrugItemRecordService.queryNonDrugItemByBillId(billId);
        NonDrugItemResult nonDrugItemResult = BeanUtil.copyProperties(nonDrugItemDto, NonDrugItemResult.class);
        return Result.getInstance(NonDrugItemResult.class).setData(nonDrugItemResult);
    }

    @Override
    public Result<Boolean> paySuccess(Long billId) {
        log.info("支付成功修改状态：{}",billId);
        Boolean bool = nonDrugItemRecordService.paySuccess(billId);
        return Result.getInstance(Boolean.class).setData(bool);
    }
}
